<ui:composition
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:nxh="http://nuxeo.org/nxweb/html"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:fn="http://java.sun.com/jsp/jstl/functions"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  xmlns:a4j="http://richfaces.org/a4j">

<ui:remove>
 Template rendering a layout listing with pagination control and selection
 actions.

  Parameters:
  - documents: the page selections instance, mandatory
  - layoutName: layout to use for listing rendering, mandatory
  - layoutTemplate: layout template to override the default layout template,
    optional, available since 5.6.
  - selectedResultLayoutColumns: list of result column names to display,
    optional, defaults to the layout default columns configuration.
  - hideTopPaginationControls: only display the bottom page selectors
    (available since 5.6).
</ui:remove>

  <c:if test="#{not hideTopPaginationControls}">
    <c:choose>
      <c:when test="#{useAjaxPagination == null or useAjaxPagination}">
        <ui:include src="/pagination/a4jPageNavigationControls.xhtml" />
      </c:when>
      <c:otherwise>
        <ui:include src="/pagination/pageNavigationControls.xhtml" />
      </c:otherwise>
    </c:choose>
  </c:if>

  <ui:insert name="empty_folder_label">
    <h:outputText value="#{messages['label.content.emptyFolder']}"
      rendered="#{documents.rowCount == 0}"
      styleClass="emptyResult emptyResultBig" />
  </ui:insert>

  <ui:insert name="error_message" />

  <c:if test="#{documents.rowCount != 0}">

    <c:if test="false">
      Resolve layout for first element just to get display and before_layout property.
    </c:if>
    <nxl:layout name="#{layoutName}" value="#{documents.rows[0]}"
      mode="view" selectedColumns="#{selectedResultLayoutColumns}"
      template="#{layoutTemplate}" resolveOnly="true">

      <c:set var="useRepeatRenderTime" value="#{configurationService.isBooleanPropertyTrue('nuxeo.jsf.listings.useRepeatRenderTime')}" />
      <c:set var="display" value="#{layoutProperty_display}" />
      <c:if
        test="#{empty display and fn:endsWith(layoutName, '_2_columns')}">
        <c:set var="display" value="table_2_columns" />
      </c:if>

      <c:if test="#{not empty layoutProperty_before_template}">
        <ui:include src="#{layoutProperty_before_template}" />
      </c:if>

      <c:choose>

        <c:when test="#{display == 'block'}">
          <div>
            <nxu:repeat var="row" items="#{documents.rows}"
              id="#{formId}_repeat"
              renderTime="#{useRepeatRenderTime}"
              varStatus="layoutListingStatus">
              <c:set var="showListingHeader"
                value="#{layoutListingStatus.index == 0}" />
              <nxl:layout layout="#{layout}" value="#{row}" />
            </nxu:repeat>
          </div>
        </c:when>

        <c:when test="#{display == 'table_2_columns'}">
          <table class="dataOutput2Columns">
            <tr>
              <td>
                <table class="dataTableNoBorder">
                  <nxu:repeat var="row" items="#{documents.rows}"
                    id="#{formId}_repeat"
                    renderTime="#{useRepeatRenderTime}"
                    varStatus="layoutListingStatus"
                    end="#{(documents.size-1)/2}">
                    <c:set var="showListingHeader"
                      value="#{layoutListingStatus.index == 0}" />
                    <nxl:layout layout="#{layout}" value="#{row}" />
                  </nxu:repeat>
                </table>
              </td>
              <td>
                <table class="dataTableNoBorder">
                  <nxu:repeat var="row" items="#{documents.rows}"
                    id="#{formId}_repeat"
                    renderTime="#{useRepeatRenderTime}"
                    varStatus="layoutListingStatus"
                    begin="#{(documents.size-1)/2 + 1}">
                    <c:set var="showListingHeader"
                      value="#{layoutListingStatus.index == documents.size/2+1}" />
                    <nxl:layout layout="#{layout}" value="#{row}" />
                  </nxu:repeat>
                </table>
              </td>
            </tr>
          </table>
        </c:when>

        <c:otherwise>
          <table class="dataOutput">
            <nxu:repeat var="row" items="#{documents.rows}"
              id="#{formId}_repeat"
              renderTime="#{useRepeatRenderTime}"
              varStatus="layoutListingStatus">
              <c:set var="showListingHeader"
                value="#{layoutListingStatus.index == 0}" />
              <nxl:layout layout="#{layout}" value="#{row}" />
            </nxu:repeat>
          </table>
        </c:otherwise>

      </c:choose>

    </nxl:layout>

  </c:if>

  <ui:insert name="pageNavigationControls">
    <c:choose>
      <c:when test="#{useAjaxPagination == null or useAjaxPagination}">
        <ui:include src="/pagination/a4jPageNavigationControls.xhtml" />
      </c:when>
      <c:otherwise>
        <ui:include src="/pagination/pageNavigationControls.xhtml" />
      </c:otherwise>
    </c:choose>
  </ui:insert>

  <ui:insert name="syndication_buttons" />

</ui:composition>